package com.wenx.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class AppCXF extends RouteBuilder {

    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new AppCXF());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    /**
     * webservice
     * @throws Exception
     */
    public void configure() throws Exception {
        from("timer:foo?repeatCount=1")
                .setBody(constant("aaabb"))             //set request body
                .to("cxf:"
                        + "http://localhost:8080/wx_service/WebService" //service address
                        + "?"
                        + "wsdlURL=http://localhost:8080/wx_service/WebService?wsdl"    //wsdl url
                        + "&"
                        + "dataFormat=RAW"        //dataformat type
                )
                .convertBodyTo(String.class)
                .to("stream:out");
    }

}
